//
//  ZYOutDoorView.m
//  YiLin
//
//  Created by Zyark on 2018/6/4.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYInDoorView.h"
#import "ZYDevice.h"

#define LEFT 15
#define MARGIN self.height * 0.1
@interface ZYInDoorView()
/**
 氧气
 */
@property(nonatomic,strong) UILabel *oxygenLabel;

/**
 TVOC
 */
@property(nonatomic,strong) UILabel *tvocLabel;

/**
 室温
 */
@property(nonatomic,strong) UILabel *roomTemperatureLabel;

/**
 湿度
 */
@property(nonatomic,strong) UILabel *humidityLabel;


/**
 甲醛
 */
@property(nonatomic,strong) UILabel *formaldehydeLabel;

/**
 普通滤网
 */
@property(nonatomic,strong) UILabel *generalFilteringLabel;

/**
 pm2.5滤网
 */
@property(nonatomic,strong) UILabel *pmFilteringLabel;


/**
 滤网Label背景
 */
@property(nonatomic,strong) UIView *filterBgView;
@end

@implementation ZYInDoorView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

-(void)setup{
    CGFloat margin = (self.height - 50) / 4;
    
    _filterBgView = [self setupFilterBgView];
    _filterBgView.centerX = self.width / 2;
    _filterBgView.bottom = self.height - margin;
    
    /**底部5个label*/
    _oxygenLabel = [self setupLabel];
    _tvocLabel = [self setupLabel];
    _roomTemperatureLabel = [self setupLabel];
    _humidityLabel = [self setupLabel];
    _formaldehydeLabel = [self setupLabel];
    
    
    _tvocLabel.left = LEFT;
    _tvocLabel.bottom = _filterBgView.top - margin;
    
    _oxygenLabel.left = _tvocLabel.left;
    _oxygenLabel.bottom = _tvocLabel.top - margin;
    
    _roomTemperatureLabel.left = _tvocLabel.right;
    _roomTemperatureLabel.bottom = _filterBgView.top - margin;
    
    _humidityLabel.left = _roomTemperatureLabel.left;
    _humidityLabel.bottom = _roomTemperatureLabel.top - margin;
    
    _formaldehydeLabel.left = _humidityLabel.right;
    _formaldehydeLabel.top = _humidityLabel.top;
    
    _pmFilteringLabel = [self setupFilterLabel];
    _generalFilteringLabel = [self setupFilterLabel];
    _generalFilteringLabel.centerY = _filterBgView.centerY;
    _generalFilteringLabel.left = _filterBgView.left + 5;
    _generalFilteringLabel.textAlignment = NSTextAlignmentRight;
    
    _pmFilteringLabel.centerY = _filterBgView.centerY;
    _pmFilteringLabel.left = _generalFilteringLabel.right + 5;
    _pmFilteringLabel.textAlignment = NSTextAlignmentLeft;
}

-(UILabel *)setupLabel{
    UILabel *label = [[UILabel alloc] init];
    label.width = (self.width - LEFT) / 3;
    label.height = 15;
    label.font = [UIFont systemFontOfSize:14];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = kDeviceLabelColor;
    [self addSubview:label];
    return label;
}

-(UIView *)setupFilterBgView{
    UIView *view = [[UIView alloc] init];
    view.height = 20;
    view.width = self.width - LEFT * 2;
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 3;
    view.layer.masksToBounds = YES;
    [self addSubview:view];
    return view;
}

-(UILabel *)setupFilterLabel{
    UILabel *label = [[UILabel alloc] init];
    label.width = (_filterBgView.width - 15) / 2;
    label.height = 13;
    label.font = [UIFont systemFontOfSize:12];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = kMainColor;
    [self addSubview:label];
    return label;
}

-(void)setDevice:(ZYDevice *)device{
    _device = device;
    ZYChangeLanguage *language = [ZYChangeLanguage sharedZYChangeLanguage];
    _oxygenLabel.text = [NSString stringWithFormat:@"CO2：%@%%",device.carbonDioxide];
    _tvocLabel.text = [NSString stringWithFormat:@"TVOC：%@",device.tvoc];
    _humidityLabel.text = [NSString stringWithFormat:@"%@：%@%%",[language getStringByKey:LC_HOME_MAIN_HUMIDITY],device.humidity];
    _roomTemperatureLabel.text = [NSString stringWithFormat:@"%@：%@℃",[language getStringByKey:LC_HOME_MAIN_ROOM_TEMPERATURE],device.roomTemperature];
    _formaldehydeLabel.text = [NSString stringWithFormat:@"%@：%@",[language getStringByKey:LC_HOME_MAIN_FORMALDEHYDE],device.formaldehyde];
    _pmFilteringLabel.text = [NSString stringWithFormat:@"%@：%@",[language getStringByKey:LC_HOME_MAIN_LABEL_FILTER_PM],device.filterPm];
    _generalFilteringLabel.text = [NSString stringWithFormat:@"%@：%@",[language getStringByKey:LC_HOME_MAIN_LABEL_FILTER_COMMON],device.filterCommon];
}


@end
